package com.hejia.alauda.persistence.mybatis;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hejia.alauda.entity.Parameter;
import com.hejia.alauda.persistence.BaseMapper;

public interface ParameterMapper extends BaseMapper<Parameter> {

	/**
	 * 判断Parameter里Custom的唯一性
	 */

	@Select("select count(*) from `parameter` p where p.`code`= #{0}")
	@ResultType(value = Integer.class)
	int judgeCustomCode(String code);
	
	@Update("UPDATE `parameter` SET `value`=#{newLock} WHERE `value`=#{currentLock} AND `code`=#{code} AND `category`=#{category}")
	int lockConfig(@Param("newLock") String newLock,@Param("currentLock") String currentLock,@Param("category") String category,@Param("code") String code);
	
	@Select("SELECT TO_DAYS(#{0})-TO_DAYS(#{1}) FROM DUAL")
	@ResultType(value = Integer.class)
	int calculateDateInterval(String date1, String date2);
}
